// pages/my/reader/index.js
const app = getApp();
const model = require('../../../utils/model');

Page({

  /**
   * 页面的初始数据
   */
  data: {
      user_avatar: "http://wx.qlogo.cn/mmhead/8hfmlX7akoWcsVBLj43BpoWicvUUSjeO2Cibd7CIbOb7Q/132",
      user_name: "大胃王",
      list: [],
      work_number: '',
      scrollHeight: 0,
      flower:2,
      praise:8, 
      rank: 100, //100名以外显示"暂无排名"
      lastId:0,
      canLoadMore:true,
      loadtips:'数据加载中...'
  },
  getDetail:function(){

  },
  getList2: function () {
    var pageSize = 10;
    var newInfo = [];
    var curInfoLen = this.data.infos.length;
    for(var i = 0; i < pageSize; i ++) {
      var info = {
        imgUrl:'http://wxbucket.oss-cn-hangzhou.aliyuncs.com/microApp/sxl-mwpd/people_rank/cover.jpg',
        title:'简爱'+(curInfoLen+i),
        praise: curInfoLen+i
      };
      newInfo.push(info);
    };
    var curInfo = this.data.infos.concat(newInfo);
    var getInfoLen = this.data.infos.length;
    this.setData({
      infos: curInfo,
      work_number: getInfoLen
    });
  },
  getList: function () {
    if (!this.data.canLoadMore){
      return;
    }
    this.data.canLoadMore = false;
    var me = this;
    model.request({
      action:'userReadingList',
      data:{
        last_id:me.data.lastId
      },
      success: function (res) {
        me.data.canLoadMore = true;

        if (res.data.list && res.data.list.length) {
          var newList = me.data.list.concat(res.data.list);
          me.setData({
            list:newList,
            lastId:res.data['last_id']
          });
        }
        else {
          me.setData({
            loadtips:'拉到最后啦！'
          });
        }
        
      }
    });
  },

  lower: function () {
    this.getList();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      scrollHeight: app.globalData.winHeight - 93
    });
    this.getDetail();
    this.getList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})